home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE18 / TIPTRIX / LISTING6.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-17  |  785 b   |  37 lines

  1. Function GetEnvVar(Const Env:String) : String;
  2. { return contents of environment variable "Env" - or an empty
  3.   string if vairable does not exist
  4.  
  5.   e.g.,
  6.   Var Command : String;
  7.   begin
  8.      Command := GetEnvVar('COMSPEC')+#0;
  9.      WinExec(@Command[1], sw_Normal);
  10.   end;
  11.  
  12. }
  13.  
  14. var
  15. p2 : pchar;
  16. i  : Word;
  17. s  : String;
  18.  
  19. Begin
  20.     Result := '';
  21.     p2 := GetDOSEnvironment;
  22.     while p2[0] <> #0 do
  23.     begin
  24.       s := StrPas(p2);
  25.       if (Pos(UpperCase(Env), UpperCase(s)) = 1) then
  26.       begin
  27.         i := Pos('=', s);
  28.         If i=0 then i := pos(#32, s);
  29.         Delete(s,1,i);
  30.         Result := s;
  31.         Exit;
  32.       end;
  33.       while (p2[0] <> #0) do Inc(p2); { goto end of current }
  34.       Inc(p2); { point to next }
  35.     end;
  36. End {GetEnvVar};
  37.